package com.cy.game

import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.TextView
import androidx.gridlayout.widget.GridLayout
import com.helloandroid.R
import com.helloandroid.base.BaseDialog

class CyListDialog(val proverbs:List<Proverb>, override var ctx:Context) : BaseDialog(ctx) {

    lateinit var gridLayout:GridLayout

    override fun getContentViewResId(): Int  = R.layout.yh_chengyu_expains

    override fun initView() {
        gridLayout = findViewById(R.id.gridLayout)
        findBtn(R.id.expains_okButton).setOnClickListener {
            cancel()
        }
    }

    override fun initData() {

        val scale = ctx.resources.displayMetrics.widthPixels / 1080f
        val margin =  (30f * scale).toInt()

        val width = ctx.resources.getDimension(R.dimen.dp80).toInt()
        val height = ctx.resources.getDimension(R.dimen.dp23).toInt()

        // 获取所有的词
        for (p in proverbs){
            val textView = TextView(ctx)
            textView.setBackgroundResource(R.drawable.yh_chengyu_expain_item)
            textView.setTextColor(Color.BLACK)
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
            textView.gravity = Gravity.CENTER

                    // LayoutInflater.from(ctx).inflate(R.layout.yh_chengyu_expain_item,gridLayout,false) as TextView
            textView.text = p.content
            val params = GridLayout.LayoutParams()
            params.width = width
            params.height = height
            params.topMargin = margin
            params.leftMargin = margin
            gridLayout.addView(textView,params)
            textView.setOnClickListener {
                ExplainDialog(ctx,p).show()
            }
        }
    }
}